package code2;

import java.io.File;

public class Code {

    public static void deleteDir(File file){

        File[] files = file.listFiles();
        String str = null;

        for(File f : files){
            str = f.getName();
            if(f.isFile()){
                f.delete();
                System.out.println("成功删除文件"+str+"!");
            }else{
                deleteDir(f);
                f.delete();
                System.out.println("成功删除目录["+str+"]!");
            }
        }
    }

    public static void main(String[] args) {

        File file = new File("F:/a");
        deleteDir(file);
        System.out.println("目录删除成功！");
    }

}


